﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Jlob.OpenErpNet;
using Jlob.OpenErpNet.Templates;
using System.Linq;
using System.Collections.Generic;
using CookComputing.XmlRpc;
using Jlob.OpenErpNet.Entities;

namespace Jlob.OpenErpNet.Test
{
    [TestClass]
    public class TemplatesTest
    {
        private const string OpenErpServer = "http://192.168.73.128:8069";
        private const string OpenerpDataBase = "POLTEST";
        private const string OpenerpUser = "admin";
        private const string OpenerpPass = "admin";

        [TestMethod]
        public void Test_Get_Entity_from_generated()
        {
            IEnumerable<product_product> em = null;
            OpenErpService openErpService = new OpenErpService(OpenErpServer, "POLTEST", "admin", "admin");
            em = openErpService.GetEntities<product_product>(e => true).Include(e => e.message_ids);
            Assert.IsNotNull(em);
        }

        [TestMethod]
        public void Test_Get_Employes_from_generated()
        {
            IEnumerable<hr_employee> em = null;
            OpenErpService openenErpService = new OpenErpService(OpenErpServer, "POLTEST", "admin", "admin");
            em = openenErpService.GetEntities<hr_employee>(e => true);
            Assert.IsTrue(em.Count() > 0);
        }

        [TestMethod]
        public void Test_EntityFactory_BuildEntity_Custom_Model()
        {
            XmlRpcStruct entityData = new XmlRpcStruct();
            entityData.Add("id", 1);
            entityData.Add("name", "Admin");
            Employee e = EntityFactory.BuildEntity<Employee>(null, entityData);
            Assert.AreEqual(e.id, 1);
            Assert.AreEqual(e.Name, "Admin");
        }

        [TestMethod]
        public void Test_EntityFactory_BuildEntity_Template_Model()
        {
            XmlRpcStruct entityData = new XmlRpcStruct();
            entityData.Add("id", 1);
            entityData.Add("name_related", "Admin");
            hr_employee e = EntityFactory.BuildEntity<hr_employee>(null, entityData);
            Assert.AreEqual(e.id, 1);
            Assert.AreEqual(e.name_related, "Admin");
        }

    }
}
